<template>
	<view>
		<view v-if="resultList.length == 0">暂无消息</view>
		<view v-else>
			<scroll-view scroll-y="true" :style="{height: wh + 'px'}" @scrolltolower="scrollLower">
				<view  v-for="(item,index) in messageList" :key="index">
					<view class="result-list" @click="toggle('center',index)">
						<!-- 左边logo -->
						<view>
							<uni-icons customPrefix="order" type="icon-hsjctixing" size="40" color="#09bb07"></uni-icons>
						</view>
						<!-- 右边信息 -->
						<view class="result-list-right">
							<view class="result-list-right-line">
								<view>{{item.hospName}}</view>
								<view v-if="item.status==0"><uni-icons customPrefix="order" type="icon-hsjcxiaoxishuzijiaobiao" color="#C00000" size="30"></uni-icons></view>
							</view>
							<view class="result-list-right-line">
								<view style="color: gray; font-size: 12px;">{{item.createTime}}</view>
							</view>
						</view>
					</view>
				</view>
				<uni-load-more :status="status"></uni-load-more>
			</scroll-view>
		</view>
		
		<!-- <button class="button" type="primary" @click="toggle('center',)"><text class="button-text">居中</text></button> -->
		<uni-popup ref="popup" background-color="#fff" @change="change">
			<view class="popup-content" 
				:class="{ 'popup-height': type === 'left' || type === 'right' }">
				
				<view>
					<view style="font-weight: bold; margin-bottom: 10px;">就医提醒</view>
					<view class="message-body">
						<view>就诊人:</view>
						<view class="message-body-text">{{messageList[messageIndex].userName}}</view>
					</view>
					<view class="message-body">
						<view>就诊医院:</view>
						<view class="message-body-text">{{messageList[messageIndex].hospName}}</view>
					</view>
					<view class="message-body">
						<view>就诊项目:</view>
						<view class="message-body-text">{{messageList[messageIndex].itemName}}</view>
					</view>
					<view class="message-body">
						<view>就诊时间:</view>
						<view class="message-body-text">{{messageList[messageIndex].orderTime + "  "}} {{messageList[messageIndex].timeId==0?'上午':'下午'}} </view>
					</view>
				</view>
				
			</view>
		</uni-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				page:1,
				limit:8,
				totalPage:0,
				messageList:[],
				status:"more",
				wh:0,
				messageIndex:-1
			};
		},
		onLoad() {
			const sysInfo = uni.getSystemInfoSync()
			this.wh = sysInfo.windowHeight
			this.getOrderMessageList()
		},
		methods:{
			change(e) {
				console.log('当前模式：' + e.type + ',状态：' + e.show);
			},
			toggle(type,index) {
				this.type = type
				this.messageIndex = index
				// open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
				this.$refs.popup.open(type)
				uni.request({
					url:"http://192.168.43.224:9002/message/updateStatus/"+this.messageList[index].messageId,
					method:'PUT',
					success: (res) => {
						this.getOrderMessageList()
					}
				})
			},
			scrollLower() {
				console.log('触发了')
			    if (this.page >= this.totalPage) {
			       this.status = "noMore"
			       return
			    } else {
			       this.status = "loading"
			    }
			    this.page++
			    this.timer = setTimeout(() => {
					this.getOrderList()
			    }, 200)
			    console.log('我滚动到底部了')
			},
			
			getOrderMessageList(){
				uni.request({
					url:'http://192.168.43.224:9002/message/getMessageList/'+this.page+"/"+this.limit,
					method:'GET',
					success: (res) => {
						this.messageList = res.data.data.records
						this.totalPage = res.data.data.pages
						console.log(this.messageList)
					}
				})
			},
		}
	}
</script>

<style lang="scss">
.message-body{
	display: flex;
	margin-bottom: 8px;
	.message-body-text{
		margin-left: 10px;
	}
}
.result-list{
	margin-top: 10px;
	width: 100%;
	height: 75px;
	display: flex;
	background-color: #EBEEF5;
	box-shadow: 5rpx #C0C4CC;
	// justify-content: center;
	align-items: center;
	padding-left: 15px;
}
.result-list-right{
	height: 100%;
	width: 100%;
	margin: 5px 10px;
	.result-list-right-line{
		display: flex;
		justify-content: space-between;
		padding-left: 10px;
		padding-right: 20px;
		padding-top: 10px;
		.result-list-right-line-price{
			color: #F0AD4E;
		}
	}
}
@mixin flex {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: row;
	}

	@mixin height {
		/* #ifndef APP-NVUE */
		height: 100%;
		/* #endif */
		/* #ifdef APP-NVUE */
		flex: 1;
		/* #endif */
	}

	.box {
		@include flex;
	}

	.button {
		@include flex;
		align-items: center;
		justify-content: center;
		flex: 1;
		height: 35px;
		margin: 0 5px;
		border-radius: 5px;
	}

	.example-body {
		background-color: #fff;
		padding: 10px 0;
	}

	.button-text {
		color: #fff;
		font-size: 12px;
	}

	.popup-content {
		@include flex;
		align-items: center;
		justify-content: center;
		padding: 15px;
		height: 250px;
		width: 300px;
		background-color: #fff;
	}

	.popup-height {
		@include height;
		width: 200px;
	}

	.text {
		font-size: 12px;
		color: #333;
	}

	.popup-success {
		color: #fff;
		background-color: #e1f3d8;
	}

	.popup-warn {
		color: #fff;
		background-color: #faecd8;
	}

	.popup-error {
		color: #fff;
		background-color: #fde2e2;
	}

	.popup-info {
		color: #fff;
		background-color: #f2f6fc;
	}

	.success-text {
		color: #09bb07;
	}

	.warn-text {
		color: #e6a23c;
	}

	.error-text {
		color: #f56c6c;
	}

	.info-text {
		color: #909399;
	}

	.dialog,
	.share {
		/* #ifndef APP-NVUE */
		display: flex;
		/* #endif */
		flex-direction: column;
	}

	.dialog-box {
		padding: 10px;
	}

	.dialog .button,
	.share .button {
		/* #ifndef APP-NVUE */
		width: 100%;
		/* #endif */
		margin: 0;
		margin-top: 10px;
		padding: 3px 0;
		flex: 1;
	}

	.dialog-text {
		font-size: 14px;
		color: #333;
	}
</style>
